layui.define([ 'form', 'laydate', 'table' ], function(exports) {
    var form = layui.form;
    var laydate = layui.laydate;
    var table = layui.table;
    var enterpriseTable = null;
    var view ={
        init:function(){
            this.initTable();
            this.initSearchForm();
            this.initToolBar();
            window.dataReload = function(){
                Lib.doSearchForm($("#searchForm"),enterpriseTable)
            }
        },
        initTable:function(){
            enterpriseTable = table.render({
                elem : '#enterpriseTable',
                height : Lib.getTableHeight(1),
                cellMinWidth: 100,
                method : 'post',
                url : Common.ctxPath + '/cms/enterprise/listMaintain.json' // 数据接口
                ,page : Lib.tablePage // 开启分页
                ,limit : 10,
                cols : [ [ // 表头
                    {
                        type : 'checkbox',
                        fixed:'left',
                    },

                {

                    field : 'enterpriseName',
                        title : '企业名称',
                    align: 'center',
                    width:"200"
                },
                {

                    field : 'organizationCode',
                        title : '统一社会信用代码',
                    align: 'center',
                    width:"200"
                },
                    {

                        field : 'dateEstablishment',
                        title : '成立日期',
                        align: 'center',
                        width:"180",
                        templet:function(d){
                            return Common.getDate(d.dateEstablishment,'yyyy-MM-dd');
                        }
                    },
                    {

                        field : 'registeredCapital',
                        title : '注册资金(万元)',
                        align: 'center',
                        width:"150",templet:function (d) {
                        return Common.getMoney(d.registeredCapital);
                        }
                    },
                   /* {

                        field : 'enterpriseLegalPerson',
                        title : '企业法人	',
                        align: 'center',
                        width:"120"
                    },*/
                    {

                        field : 'registrationNumber',
                        title : '营业执照注册号',
                        align: 'center',
                        width:"200"
                    },
                    {
                        field : 'state',
                        title : '状态',
                        align: 'center',
                        width:"135"
                    }


                ] ]

        });

            table.on('checkbox(enterpriseTable)', function(obj){
                var enterprise = obj.data;
                if(obj.checked){
                    //按钮逻辑Lib.buttonEnable()
                }else{

                }
            })
        },

        initSearchForm:function(){
            Lib.initSearchForm( $("#searchForm"),enterpriseTable,form);
        },
        initToolBar:function(){
            toolbar = {
                add : function() { // 获取选中数据
                    var url = "/cms/enterprise/add.do";
                    Common.openDlg(url,"Enterprise>新增");
                },
                edit : function() { // 获取选中数目
                    var data = Common.getOneFromTable(table,"enterpriseTable");
                    if(data==null){
                        return ;
                    }
                    var url = "/cms/enterprise/edit.do?id="+data.id;
                    Common.openDlg(url,"企业>编辑");
                },
                exportDocument : function() {
                    layui.use([ 'enterpriseApi' ], function() {
                        var testApi = layui.enterpriseApi
                        Common.openConfirm("确认要导出这些企业数据?", function() {
                            testApi.exportExcel($("#searchForm"), function(fileId) {
                                Lib.download(fileId);
                            })
                        })
                    });
                },
                importDocument:function(){
                    var uploadUrl = Common.ctxPath+"/cms/enterprise/excel/import.do";
                    //模板,
                    var templatePath= "/admin/enterprise/enterprise_upload_template.xls";
                    //公共的简单上传文件处理
                    var url = "/core/file/simpleUpload.do?uploadUrl="+uploadUrl+"&templatePath="+templatePath;
                    Common.openDlg(url, "企业>上传");
                },
                invalid : function() {//禁用
                    layui.use(['del'], function(){
                        var delView = layui.del
                        delView.invalid();
                    });
                },
                del : function() {
                    layui.use(['del'], function(){
                        var delView = layui.del
                        delView.delBatch();
                    });
                }
        };
            $('.ext-toolbar').on('click', function() {
                var type = $(this).data('type');
                toolbar[type] ? toolbar[type].call(this) : '';
            });
        }
    }
    exports('indexMaintain',view);

});